<template>
  <div class="buttonAddExitone">
    <el-button type="primary" size="mini" @click="dialogFormVisibleAdd=true"> 附件 </el-button>
    <el-dialog :close-on-click-modal="false"  title="下载附件" :visible.sync="dialogFormVisibleAdd"  @close="resetForm('ruleFormAdd')" @open="getAgencyInfo">
      <el-form :model="ruleFormAdd" :rules="rulesAdd" ref="ruleFormAdd" label-width="90px" class="demo-ruleForm">
        <el-form-item label="报送单位" prop="agencyId" :rules="{required: true, message: '请选择报送单位', }">
          <el-select v-model="ruleFormAdd.agencyId" style="width: 100%;margin-top: 3px;" size="mini" clearable placeholder="全部">
            <el-option
              v-for="item in options"
              :key="item.agencyId"
              :label="item.agencyName"
              :value="item.agencyId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item  >
          <span @click="submitForm('ruleFormAdd')"> <i class="el-icon-document" style="font-size: 20px;margin-right: 10px;color:#3975FE;"></i><span style="color:#3975FE;cursor: pointer;">评分依据附件</span></span>
        </el-form-item>
      </el-form>
      <div style="text-align: center;margin-top: 20px;">
        <el-button  size="small" @click="dialogFormVisibleAdd = false">取 消</el-button>
        <el-button style="margin-left: 20px;" type="primary" size="small" @click="submitForm('ruleFormAdd')">下 载</el-button>
      </div>


    </el-dialog>
  </div>
</template>

<script>

  export default {
    props:["taskId"],
    data () {
      return {
        options: [],
//        taskId: 1,
        props: {
          value: '4',
          label: '城管局',
          children: 'items'
        },
        ruleFormAdd: {
          "agencyId": "",

        },
        dialogFormVisibleAdd: false,
        rulesAdd: { }
      }
    },
    created(){

    },
    methods: {
    //获取所有单位
      getAgencyInfo(){

        // this.axios.post(process.env.API_HOST + `/common/selectExamineAgencyList`, {})
        //   .then(response => {
        //     const result = response.data
        //     if (result.code == 200) {
        //       this.options = result.result
        //     }
        //   })
      },
      //提交回调
      handleDiaSureAdd(){
        let url=process.env.API_HOST + `/examine/selectAgencyAttachment?taskId=${this.taskId}&agencyId=${this.ruleFormAdd.agencyId}`
        this.axios.get(url)
          .then(response => {
            let result=response.data
            let sign=this.md5(`agencyId=${this.ruleFormAdd.agencyId}&taskId=${this.taskId}&key=a8953039d236276bc3a8344009f4a485`, 'UTF-8').toUpperCase()
            if(!result.code&&result.code!=1500){
              window.location.href=url+"&sign="+sign
              this.$message({
                type: 'warning',
                message: '下载成功!'
              });
            }

          })
          .catch(error => {
            console.log(error);
          });
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.handleDiaSureAdd()
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus" >
  @import "../../../common/stylus/mixin.styl"
  .buttonAddExitone
    display inline-block
    margin-left 10px
    .el-dialog
      width:400px !important;
</style>
